﻿@page
@using Volo.Abp.Account.Settings
@using Volo.Abp.Settings
@using Microsoft.Extensions.Localization
@using Microsoft.Extensions.Options
@using Volo.Abp.AspNetCore.Mvc.AntiForgery
@using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.Localization
@using Volo.Abp.AspNetCore.MultiTenancy
@using Volo.Abp.MultiTenancy
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Components
@using Volo.Abp.Account.Localization
@using Microsoft.AspNetCore.Mvc.Localization

@using Coso.Abp.Theme.AdminLTE.Themes.AdminLTE.Components.PageAlerts
@using Coso.Abp.Theme.AdminLTE.Themes.AdminLTE.Components.Toolbar.LanguageSwitch
@model Volo.Abp.Account.Web.Pages.Account.LoginModel
@inject IHtmlLocalizer<AccountResource> L
@inject Volo.Abp.Settings.ISettingProvider SettingProvider
@inject IAbpAntiForgeryManager AbpAntiForgeryManager
@inject IOptions<AbpMultiTenancyOptions> MultiTenancyOptions
@inject ICurrentTenant CurrentTenant
@inject IStringLocalizer<AbpUiMultiTenancyResource> MultiTenancyStringLocalizer
@inject ITenantResolveResultAccessor TenantResolveResultAccessor
@inject IBrandingProvider BrandingProvider


<abp-row>
    <abp-column class="login">
        <div class="account-brand p-3 text-center mb-1">
            <a routerlink="/" alt="MyProjectName" class="navbar-brand" href="/">
                <img src="@(string.IsNullOrWhiteSpace(Url.Content(BrandingProvider.LogoUrl)) ? "/themes/adminlte/img/AdminLTELogo.png" : Url.Content(BrandingProvider.LogoUrl))"
                     alt="AdminLTE Logo" class="brand-image img-circle elevation-3"
                     style="opacity: .8;height:50px;">
            </a>
        </div>
        <div class="card">
            <div class="card-header">
                <h2 class="card-title d-inline-block">@L["Login"]</h2>
                <nav class="navbar navbar-expand p-0 pt-1 float-right">
                    <ul class="navbar-nav ml-auto toolbar-nav">
                        @(await Component.InvokeAsync<LanguageSwitchViewLoginComponent>())
                    </ul>
                </nav>
            </div>

            <div class="card-header bg-light ">
                <div class="tenant-switch-box">
                    <div class="row">
                        <div class="col pr-1">
                            <h6 class="m0"> @MultiTenancyStringLocalizer["Tenant"] </h6>
                            @if (CurrentTenant.Id == null)
                            {
                                <i>
                                    @MultiTenancyStringLocalizer["NotSelected"]
                                </i>
                            }
                            else
                            {
                                <strong>@(CurrentTenant.Name ?? CurrentTenant.Id.Value.ToString())</strong>
                            }
                        </div>
                        <div class="col-auto pl-1">
                            @if (MultiTenancyOptions.Value.IsEnabled &&
(TenantResolveResultAccessor.Result?.AppliedResolvers?.Contains(CookieTenantResolveContributor.ContributorName) == true))
                            {
                                <a id="AbpTenantSwitchLink" href="javascript:;" class="btn btn-sm mt-3 btn-outline-primary">@MultiTenancyStringLocalizer["Switch"]</a>
                            }
                        </div>
                    </div>
                </div>
            </div>

            <div class="card-body">
                <form method="post" class="mb-3">

                    <div class="form-group">
                        <label asp-for="LoginInput.UserNameOrEmailAddress"></label>
                        <input asp-for="LoginInput.UserNameOrEmailAddress" class="form-control" />
                        <span asp-validation-for="LoginInput.UserNameOrEmailAddress" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="LoginInput.Password"></label>
                        <input asp-for="LoginInput.Password" class="form-control" />
                        <span asp-validation-for="LoginInput.Password" class="text-danger"></span>
                    </div>
                    <abp-row>
                        <abp-column>
                            <abp-input asp-for="LoginInput.RememberMe" class="mb-4" />
                        </abp-column>
                        <abp-column class="text-right">
                            <a href="@Url.Page("./ForgotPassword", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["ForgotPassword"]</a>
                        </abp-column>
                    </abp-row>
                    <abp-button type="submit" button-type="Primary" name="Action" value="Login" class="btn-block btn-lg mt-3">@L["Login"]</abp-button>
                    <input asp-for="ReturnUrl" />
                    <input asp-for="ReturnUrlHash" />
                </form>


                @if (await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled))
                {
                    <strong style="margin-top:10px;">
                        @L["AreYouANewUser"]
                        <a href="@Url.Page("./Register", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})" class="text-decoration-none">@L["Register"]</a>
                    </strong>
                }
                @if (Model.VisibleExternalProviders.Any())
                {
                    <div class="col-md-6">
                        <h4>@L["UseAnotherServiceToLogIn"]</h4>
                        <form asp-page="./Login" asp-page-handler="ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" asp-route-returnUrlHash="@Model.ReturnUrlHash" method="post">
                            <input asp-for="ReturnUrl" />
                            <input asp-for="ReturnUrlHash" />
                            @foreach (var provider in Model.VisibleExternalProviders)
                            {
                                <button type="submit" class="btn btn-primary" name="provider" value="@provider.AuthenticationScheme" title="@L["GivenTenantIsNotAvailable", provider.DisplayName]">@provider.DisplayName</button>
                            }
                        </form>
                    </div>
                }
                @if (!Model.EnableLocalLogin && !Model.VisibleExternalProviders.Any())
                {
                    <div class="alert alert-warning">
                        <strong>@L["InvalidLoginRequest"]</strong>
                        @L["ThereAreNoLoginSchemesConfiguredForThisClient"]
                    </div>
                }

            </div>
        </div>
        @(await Component.InvokeAsync<PageAlertsViewComponent>())
    </abp-column>
</abp-row>






